package com.afei.bottomtabbar.style3;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;

import com.afei.bottomtabbar.BlankFragment;
import com.afei.bottomtabbar.MainActivity;
import com.afei.bottomtabbar.R;
import com.afei.bottomtabbar.SignActivity;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.jude.rollviewpager.hintview.ColorPointHintView;
import com.makeramen.roundedimageview.RoundedImageView;

public class Style3Activity extends AppCompatActivity {

    private RadioGroup mTabRadioGroup;
    private SparseArray<Fragment> mFragmentSparseArray;
    private RollPagerView mRollViewPager;
    private TextView tv_roll;

    private RadioButton today_tab1;
    private RadioButton today_tab2;
    private RadioButton today_tab3;
    private RadioButton today_tab4;
    private RadioButton today_tab5;
    private RadioButton today_tab6;
    private RoundedImageView r_iv,r_iv2,r_iv3;
    private TextView tv1,tv2,tv3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_style3);
        tv_roll = findViewById(R.id.tv_roll);
        today_tab1 =  findViewById(R.id.today_tab1);
        today_tab2 =  findViewById(R.id.today_tab2);
        today_tab3 =  findViewById(R.id.today_tab3);
        today_tab4 =  findViewById(R.id.today_tab4);
        today_tab5 =  findViewById(R.id.today_tab5);
        today_tab6 =  findViewById(R.id.today_tab6);
        r_iv =  findViewById(R.id.r_iv);
        tv1 =  findViewById(R.id.tv1);
        r_iv2 =  findViewById(R.id.r_iv2);
        tv2 =  findViewById(R.id.tv2);
        r_iv3 =  findViewById(R.id.r_iv3);
        tv3 =  findViewById(R.id.tv3);
        initView();
        work();

    }

    private void work() {
        mRollViewPager =  findViewById(R.id.roll_view_pager);

        //设置播放时间间隔
        mRollViewPager.setPlayDelay(1000);
        //设置透明度
        mRollViewPager.setAnimationDurtion(500);
        //设置适配器
        mRollViewPager.setAdapter(new TestNormalAdapter());

        //设置指示器（顺序依次）
        //自定义指示器图片
        //设置圆点指示器颜色
        //设置文字指示器
        //隐藏指示器
        //mRollViewPager.setHintView(new IconHintView(this, R.drawable.point_focus, R.drawable.point_normal));
        mRollViewPager.setHintView(new ColorPointHintView(this, Color.YELLOW,Color.WHITE));
        //mRollViewPager.setHintView(new TextHintView(this));
        //mRollViewPager.setHintView(null);
    }

    public class TestNormalAdapter extends StaticPagerAdapter {
        private int[] imgs = {
                R.drawable.img1,
                R.drawable.img2,
                R.drawable.img3,
                R.drawable.img4,
        };


        @Override
        public View getView(ViewGroup container, int position) {
            ImageView view = new ImageView(container.getContext());
            view.setImageResource(imgs[position]);
            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            return view;
        }


        @Override
        public int getCount() {
            return imgs.length;
        }
    }

    private void initView() {
        mTabRadioGroup = findViewById(R.id.tabs_rg);
        mFragmentSparseArray = new SparseArray<>();
        mFragmentSparseArray.append(R.id.today_tab, BlankFragment.newInstance(""));
        mFragmentSparseArray.append(R.id.record_tab, BlankFragment.newInstance("预约挂号"));
        mFragmentSparseArray.append(R.id.contact_tab, BlankFragment.newInstance("智慧诊室"));
        mFragmentSparseArray.append(R.id.settings_tab, BlankFragment.newInstance("我的"));
        mTabRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // 具体的fragment切换逻辑可以根据应用调整，例如使用show()/hide()
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        mFragmentSparseArray.get(checkedId)).commit();
            }
        });
        // 默认显示第一个
        getSupportFragmentManager().beginTransaction().add(R.id.fragment_container,
                mFragmentSparseArray.get(R.id.today_tab)).commit();
        findViewById(R.id.sign_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Style3Activity.this, SignActivity.class));
            }
        });
    }


}
